package com.smarttiger.zero.admin.dao;

import com.smarttiger.zero.admin.entity.InterfaceUsersGroupModel;
import com.smarttiger.zero.admin.entity.UsersGroupModel;
import com.smarttiger.zero.admin.entity.UsersModel;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface InterfaceUsersGroupDao extends BaseDao<InterfaceUsersGroupModel> {

    public List<InterfaceUsersGroupModel> findAllByInterfaceId(String interfaceId);


    @Modifying
    @Query("delete from InterfaceUsersGroupModel es where es.interfaceId = ?1")
    public void deleteByInterfaceId(String id);


    @Query("select u from UsersGroupModel u inner join InterfaceUsersGroupModel bl on u.id = bl.userGroupId where bl.interfaceId = ?1 ")
    public List<UsersGroupModel> queryUserGroupListModelByInterfaceId(String interfaceId);

    @Query("select u from UsersModel u left join UsersUsersGroupModel uug on uug.usersId = u.id where uug.userGroupId = ?1 ")
    public List<UsersModel> queryUsersByGroupId(String groupid);
}
